package com.insurance.controller;

import com.insurance.common.Contants;
import com.insurance.common.ResultData;
import com.insurance.pojo.InsuranceCom;
import com.insurance.service.BankService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User1: 李辽
 * Date: 2020/10/27 19:59
 * Description:保险公司相关配置
 * Version: V1.0
 */
@Api(value = "保险公司相关配置",tags = "保险公司相关配置API")
@Controller
public class BankController {

    @Autowired
    private BankService bankService;
    @RequestMapping(value = "/addinsuranceCom.do",method = RequestMethod.POST)
    @ApiOperation(value = "添加保险公司信息",notes = "添加保险公司信息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData addinsuranceCom(@RequestBody InsuranceCom insuranceCom){
        ResultData resultData = new ResultData();
        System.out.println("从前端获取的数据为："+insuranceCom);
        int result = bankService.addinsuranceCom(insuranceCom);
        if (result>0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("添加成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("添加失败");
        }
        return resultData;
    }

    @RequestMapping(value = "/queryinsuranceCom.do",method = RequestMethod.GET)
    @ApiOperation(value = "通过保险公司名称查询公司信息或者查询所有信息保险公司",notes = "按公司名查询或者查询所有公司信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "insurance_com_name",value = "保险公司名称",dataType = "String",paramType = "query"),
    })
    @ResponseBody
    public ResultData queryinsuranceCom( String insurance_com_name){
        ResultData resultData = new ResultData();
        List<Map> mapList = bankService.queryinsuranceCom(insurance_com_name);
        if (mapList != null){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
            resultData.setData(mapList);
        }else{
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查询失败");
        }
        return resultData;
    }

    @RequestMapping(value = "/queryBankName.do",method = RequestMethod.GET)
    @ApiOperation(value = "添加保险公司时判断该公司是否已经存在",notes = "添加保险公司时判断该公司是否已经存在信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="该公司已存在，不可重复添加"),
            @ApiResponse(code=500,message="该公司已存在，可添加"),

    })
    @ResponseBody
    public ResultData queryBankName(String insurance_com_name){
        System.out.println("========从前端传来的保险公司名称为："+insurance_com_name);
        ResultData resultData = new ResultData();
        List<Map>  resultName = bankService.queryBankName(insurance_com_name);
        if (resultName.size() > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("该公司已存在，不可重复添加");
        }else{
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("该公司名可添加");
        }
        return resultData;
    }


    @RequestMapping(value = "/updateInsuranceCom.do",method = RequestMethod.POST)
    @ApiOperation(value = "更改保险公司信息",notes = "更改保险公司信息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ResponseBody
    public ResultData updateInsuranceCom(@RequestBody InsuranceCom insuranceCom){
        ResultData resultData = new ResultData();
        System.out.println("从前端获取到的数据为"+insuranceCom);

        int result = bankService.updateInsuranceCom(insuranceCom);
        if (result > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("更改成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("更改失败");
        }
        return resultData;
    }


}
